<template>
	<div class="c-text" :style="[borderRadius,boxShadow,style_lh]">
		<p class="text-content" :style="linkStyle | calcStyle" v-html="cm.props.text"></p>
	</div>
</template>

<script>
	// 防抖函数
	import {
		debounce
	} from '../utils.js'
	
	export default {
		name: 'BaseFont',
		props: {
			compid: {
				type: [String, Number],
				required: true
			}
		},
		data() {
			return {
				property_value: this.$store.getters.getCompConfigByCompid(this.compid),
				old_property_val: null
			}
		},

		computed: {
			cm() {
				return this.$store.getters.getCompConfigByCompid(this.compid)
			},
			linkStyle() {
				const css = this.cm.css
				return {
					ft: css.ft
				}
			},
			borderRadius() {
				return {
					borderRadius: this.cm.css.bd.r + 'px'
				}
			},
			boxShadow() {
				return {
					boxShadow: this.cm.css.bsd.x + 'px' + ' ' + this.cm.css.bsd.y + 'px' + ' ' + this.cm.css.bsd.s + 'px' + ' ' + this
						.cm.css.bsd.p + 'px' + ' ' + this.cm.css.bsd.c
				}
			},
			style_lh() {
				return {
					lineHeight: this.cm.css.lh.h+ 'px'
				}
			}

		},
		watch: {
			property_value: {
				handler(new_val, old_val) {
					this.change_component({
						new_val,
						old_val
					});
				},
				deep: true,
				immediate: true
			}
		},
		methods: {
			change_component: debounce(function(
				params
			) {
				const revoke_state = this.$store.getters.revoke_state
				if (this.old_property_val) {
					// 表示是撤销状态的值的更新
					if (revoke_state) {
						this.$store.commit('REVOKE_STATE', false)
					} else {
						this.$store.commit('ADD_REVOKE_CONTENT', this.old_property_val)
					}
				}
				this.old_property_val = JSON.parse(JSON.stringify(params.new_val))
			}, 300)

		}

	}
</script>
<style>

</style>
